package com.eh.command.command.impl;

import com.eh.command.command.Command;
import com.eh.command.electric.CellingFan;
import com.eh.command.util.OperationHistoryUtil;

/**
 * Created by David on 2016/4/30.
 */
public class CellingFanCommand implements Command {
    private CellingFan cellingFan;
    private boolean start;

    public CellingFanCommand(CellingFan cellingFan) {
        this.cellingFan = cellingFan;
    }

    @Override
    public void execute() {
        if (start) {
            OperationHistoryUtil.record(cellingFan, "off");
            start = false;
        }
        int nextSpeed = (cellingFan.getSpeed() + 1) % 4;
        switch (nextSpeed) {
            case CellingFan.HIGH:
                cellingFan.high();
                OperationHistoryUtil.record(cellingFan, "high");
                break;
            case CellingFan.MEDIUM:
                cellingFan.medium();
                OperationHistoryUtil.record(cellingFan, "medium");
                break;
            case CellingFan.LOW:
                cellingFan.low();
                OperationHistoryUtil.record(cellingFan, "low");
                break;
            case CellingFan.OFF:
                cellingFan.off();
                OperationHistoryUtil.record(cellingFan, "off");
                break;
        }
    }

    @Override
    public String toString() {
        return "吊扇控制器";
    }
}
